package com.nhjf.dao.teachers;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.ReviewPaintingCollection;
import com.nhjf.pojo.qo.teachers.ReviewPaintingCollectionQo;
@Repository
public class ReviewPaintingCollectionDao extends BaseDao<ReviewPaintingCollection, ReviewPaintingCollectionQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, ReviewPaintingCollectionQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("reviewPaintingId", qo.isSeachReviewPainting()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("userId", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getUserId()!=null) {
				criteria.add(Restrictions.eq("userId.id",qo.getUserId()));
			}
			if(qo.getReviewPaintingid()!=null) {
				criteria.add(Restrictions.eq("reviewPaintingId.id",qo.getReviewPaintingid()));
			}
			if(qo.getCollectionUserType()!=null) {
				criteria.add(Restrictions.eq("collectionUserType",qo.getCollectionUserType()));
			}
			if(qo.getReviewPaintingCollectionId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getReviewPaintingCollectionId()));
			}
		}
		return criteria;
	}

	@Override
	protected Class<ReviewPaintingCollection> getEntityClass() {
		// TODO Auto-generated method stub
		return ReviewPaintingCollection.class;
	}

}
